package com.service.creditcard.controller;

import com.alibaba.fastjson2.JSON;
import com.client.model.pojo.user.ArUser;
import com.client.model.vo.common.Result;
import io.swagger.v3.core.util.Json;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;
import java.util.concurrent.TimeUnit;

/**
 * @Author : RulerWood
 * @Data : 2024/4/3 - 13:46
 */
@RestController
@RequestMapping("airui/api/creditcard/common")
@Tag(name = "信用卡公共接口")
public class CommonController {
    @Autowired
    private RedisTemplate<String,String> redisTemplate;

    /**
     * 发送手机验证码
     * @return
     */
    @GetMapping("/getCode")
    @Operation(summary = "验证码获取")
    public Result getCode(@RequestHeader("token") String token){
        Random random=new Random();
        String code="";
        for (int i = 0; i < 4; i++) {
            code+=random.nextInt(10);
        }
        String s = redisTemplate.opsForValue().get("user:login" + token);
        ArUser arUser = JSON.parseObject(s, ArUser.class);
        System.err.println(arUser);
        //手机验证码保存的key、value
        redisTemplate.opsForValue().set(arUser.getMobile()+":"+token,code,3, TimeUnit.MINUTES);
        return Result.build(null,200,"发送成功");
    }

}
